import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'index.dart';

class HomePage extends GetView<HomeController> {
  const HomePage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    // return ListView.builder(
    //   itemBuilder: (context, index) => ListTile(
    //       title:
    //           Text(controller.tokenList.data?.drchenggong[index].tkno ?? '')),
    //   itemCount: controller.tokenList.data?.drchenggong.length,
    // );
    return SingleChildScrollView(
      child: DataTable(
        columns: const <DataColumn>[
          DataColumn(
            label: Text('Token号'),
          ),
        ],
        rows: List<DataRow>.generate(
          controller.tokenList.data?.drchenggong != null
              ? controller.tokenList.data!.drchenggong.length
              : 0,
          (int index) => DataRow(
            color: MaterialStateProperty.resolveWith<Color?>(
                (Set<MaterialState> states) {
              // All rows will have the same selected color.
              if (states.contains(MaterialState.selected)) {
                // return Theme.of(context).colorScheme.primary.withOpacity(0.08);
              }
              // Even rows will have a grey color.
              if (index.isEven) {
                return Colors.grey.withOpacity(0.3);
              }
              return null; // Use default value for other states and odd rows.
            }),
            cells: <DataCell>[
              DataCell(
                  Text('$controller.tokenList.data!.drchenggong[index].tkno'))
            ],
            // selected: selected[index],
            onSelectChanged: (bool? value) {
              // setState(() {
              //   selected[index] = value!;
              // });
            },
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
      init: HomeController(),
      id: "home",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: const Text("首页"),
            actions: [
              IconButton(
                  onPressed: () => {Get.toNamed('/login')},
                  icon: const Icon(Icons.logout))
            ],
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
